package study.cell_game.objects.textures;

import org.andengine.engine.Engine;
import org.andengine.opengl.texture.TextureOptions;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.andengine.opengl.texture.region.TextureRegion;
import org.andengine.ui.activity.BaseGameActivity;

import study.cell_game.enums.PlayerColor;

public class TokenTextures {

	private BitmapTextureAtlas textureAtlas;
	
	private TextureRegion triangularInOutRot1;
	private TextureRegion triangularInOutRot2;

	private TextureRegion straightInOutRot1;
	private TextureRegion straightInOutRot2;
	private TextureRegion straightInOutRot3;

	private TextureRegion triangleInTriangleOutRot1;
	private TextureRegion triangleInTriangleOutRot2;

	private TextureRegion proc1;
	private TextureRegion proc2;
	private TextureRegion proc3;

	private TextureRegion ram1;

	private TextureRegion rotate;
	private TextureRegion overtake;
	
	private TextureRegion fullRing;

	private TextureRegion redPlayerTokenBackground;
	private TextureRegion greenPlayerTokenBackground;
	private TextureRegion bluePlayerTokenBackground;
	
	private TextureRegion field;
	
	private TextureRegion blueArrow;
	private TextureRegion redArrow;
	private TextureRegion rotateArrow;
	
	
	private static TokenTextures instance;

	public static TokenTextures getInstance(final BaseGameActivity activity, final Engine engine) {
		if (instance == null) {
			instance = new TokenTextures(activity, engine);
		}
		return instance;
	}

	public static TokenTextures getInstance() {
		return instance;

	}

	private TokenTextures(final BaseGameActivity activity, final Engine engine) {
		// create atlas
		this.textureAtlas = new BitmapTextureAtlas(engine.getTextureManager(), 2048, 2048,
				TextureOptions.BILINEAR_PREMULTIPLYALPHA);

		// token rings
		//'fork' type
		this.triangularInOutRot1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/OuterRings/TriangleInOutRing.png", 0, 0);
		this.triangularInOutRot2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/OuterRings/TriangleInOutRingMirroredWE.png", 80, 0);
		
		//straight-through communication
		this.straightInOutRot1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/OuterRings/StraightInOutRingRotNS.png", 160, 0);
		this.straightInOutRot2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/OuterRings/StraightInOutRingRotNWSE.png", 240, 0);
		this.straightInOutRot3 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/OuterRings/StraightInOutRingRotNESW.png", 320, 0);
		
		// inbound or outbound ways on each side
		this.triangleInTriangleOutRot1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/OuterRings/TriangleInTriangleOutRing.png", 400, 0);
		this.triangleInTriangleOutRot2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/OuterRings/TriangleInTriangleOutRingMirroredWE.png", 480, 0);
		
		// full ring -> WARNING - has untypical place on the atlas
		this.fullRing = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/OuterRings/FullRing.png", 480, 68);
		
		//cores
		this.proc1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/TokenCores/1ProcCore.png", 0, 68);
		this.proc2 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/TokenCores/2ProcCore.png", 80, 68);
		this.proc3 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/TokenCores/3ProcCore.png", 160, 68);
		this.ram1 = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/TokenCores/MemoryCore.png", 240, 68);
		this.rotate = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/TokenCores/RotateCore.png", 320, 68);
		this.overtake = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/TokenCores/OvertakeCore.png", 400, 68);
		
		//color backgrounds
		this.redPlayerTokenBackground = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/BackgroundColors/TokenRed.png", 0, 136);
		this.greenPlayerTokenBackground = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/BackgroundColors/TokenGreen.png", 80, 136);
		this.bluePlayerTokenBackground = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/BackgroundColors/TokenBlue.png", 160, 136);
		
		this.field = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/Field.png", 240, 136);
		
		//arrows
		this.blueArrow = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/other/arrow_blue.png", 0, 204);
		this.redArrow = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/other/arrow_red.png", 25, 204);
		this.rotateArrow = BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.textureAtlas,
				activity, "gfx/other/rotate.png", 50, 204);
		
		engine.getTextureManager().loadTexture(textureAtlas);
	}

	
	public TextureRegion getTriangularInOutRot1() {
		return triangularInOutRot1;
	}

	public TextureRegion getTriangularInOutRot2() {
		return triangularInOutRot2;
	}

	public TextureRegion getStraightInOutRot1() {
		return straightInOutRot1;
	}

	public TextureRegion getStraightInOutRot2() {
		return straightInOutRot2;
	}

	public TextureRegion getStraightInOutRot3() {
		return straightInOutRot3;
	}

	public TextureRegion getTriangleInTriangleOutRot1() {
		return triangleInTriangleOutRot1;
	}

	public TextureRegion getTriangleInTriangleOutRot2() {
		return triangleInTriangleOutRot2;
	}

	public TextureRegion getProc1() {
		return proc1;
	}

	public TextureRegion getProc2() {
		return proc2;
	}

	public TextureRegion getProc3() {
		return proc3;
	}

	public TextureRegion getRam1() {
		return ram1;
	}

	public TextureRegion getRotate() {
		return rotate;
	}

	public TextureRegion getOvertake() {
		return overtake;
	}

	public TextureRegion getFullRing() {
		return fullRing;
	}

	public TextureRegion getRedPlayerTokenBackground() {
		return redPlayerTokenBackground;
	}

	public TextureRegion getGreenPlayerTokenBackground() {
		return greenPlayerTokenBackground;
	}

	public TextureRegion getBluePlayerTokenBackground() {
		return bluePlayerTokenBackground;
	}

	public TextureRegion getField() {
		return field;
	}
	
	public TextureRegion getTokenBackgroundForPlayer(PlayerColor player){
		switch(player){
		case RED:
			return getRedPlayerTokenBackground();
		case GREEN:
			return getGreenPlayerTokenBackground();
		case BLUE:
			return getBluePlayerTokenBackground();
		default:
			return null;
		}
	}

	public TextureRegion getBlueArrow() {
		return blueArrow;
	}

	public TextureRegion getRedArrow() {
		return redArrow;
	}
	
	public TextureRegion getRotateArrow() {
		return rotateArrow;
	}

	
}
